#include <jni.h>
#include <string>
#include <android/input.h>
#include <android/log.h>
#include "slab.hpp"
#include "AudioEngine.h"

#define  printf(...)  __android_log_print(ANDROID_LOG_DEBUG, "jni-bridge.cpp", __VA_ARGS__)

extern "C" JNIEXPORT jstring JNICALL
Java_com_example_wi_1fipartyandroid_MainActivity_stringFromJNI(
        JNIEnv* env,
        jobject /* this */) {
    std::string hello = "Hello from C++";
    return env->NewStringUTF(hello.c_str());
}

// Initializing global variable with multiple threads
// causes segmentation fault ...
AudioEngine *audioEngine = nullptr;



extern "C" {
    JNIEXPORT void JNICALL
    Java_com_example_wi_1fipartyandroid_MainActivity_startPlaying(JNIEnv *env, jobject self/* this */) {
        audioEngine->startPlaying();
    }

    JNIEXPORT void JNICALL
    Java_com_example_wi_1fipartyandroid_MainActivity_stopPlaying(JNIEnv *env, jobject self/* this */) {
        audioEngine->stopPlaying();
    }

    JNIEXPORT void JNICALL
    Java_com_example_wi_1fipartyandroid_MainActivity_startRecording(JNIEnv *env, jobject self/* this */) {
        audioEngine->startRecording();
    }

    JNIEXPORT void JNICALL
    Java_com_example_wi_1fipartyandroid_MainActivity_stopRecording(JNIEnv *env, jobject self/* this */) {
        audioEngine->stopRecording();
    }
    JNIEXPORT void JNICALL
    Java_com_example_wi_1fipartyandroid_MainActivity_test_1slab(JNIEnv *env, jobject self /* this */){

    }
    JNIEXPORT void JNICALL
    Java_com_example_wi_1fipartyandroid_MainActivity_initializeAudioEngine(JNIEnv *env, jobject self) {
        audioEngine=new AudioEngine();
    }
}

